package com.huanletao.sync.lock02;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        ProductLock productLock = new ProductLock();
        new Thread(new Productor(productLock),"生产者01").start();
        new Thread(new Consumer(productLock),"消费者01").start();
        new Thread(new Consumer(productLock),"消费者02").start();
        new Thread(new Consumer(productLock),"消费者03").start();
        new Thread(new Productor(productLock),"生产者02").start();

     //   Thread.sleep(100000);
    }
}

class Productor implements Runnable{

    private ProductLock productLock;

    public Productor(ProductLock productLock) {
        this.productLock = productLock;
    }

    @Override
    public void run() {
        while (true) productLock.produce();
    }
}

class Consumer implements Runnable{

    public Consumer(ProductLock productLock) {
        this.productLock = productLock;
    }

    private ProductLock productLock;
    @Override
    public void run() {
        while (true) productLock.consume();
    }
}
